package com.anlu.base.mapper;

import com.anlu.base.mapper.mappermodel.dto.DemoDTO;
import com.anlu.base.mapper.mappermodel.entity.DemoEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * <p>
 * Description:TODO 详细描述
 * <p>
 * <p>
 *
 * @author anlu
 * @date 2024/9/23 13:59
 */
// @Mapper
public interface DemoConvert {

    DemoConvert INSTANCE = Mappers.getMapper(DemoConvert.class);

    /**
     * DTO -> eneity
     */
    @Mappings(value = {
            @Mapping(source = "fieldA",target = "fieldD"),
            @Mapping(source = "fieldB",target = "fieldE"),
            @Mapping(source = "fieldC",target = "fieldF")
    })
    DemoEntity dto2Entiry(DemoDTO demoDTO);

    /**
     * Entiry->DTO
     */
    @Mappings(value = {
            @Mapping(source = "fieldD", target = "fieldA"),
            @Mapping(source = "fieldE", target = "fieldB"),
            @Mapping(source = "fieldF", target = "fieldC"),
    })
    DemoDTO entity2dto(DemoEntity demoEntity);

    /**
     * 集合转换支持
     */
    @Mappings(value = {
            @Mapping(source = "fieldD", target = "fieldA"),
            @Mapping(source = "fieldE", target = "fieldB"),
            @Mapping(source = "fieldF", target = "fieldC"),
    })
    List<DemoDTO> entiry2dto(List<DemoEntity> demoEntities);

    /**
     * List <DTO -> ENTITY>
     */
    @Mappings(value = {
            @Mapping(source = "fieldA",target = "fieldD"),
            @Mapping(source = "fieldB",target = "fieldE"),
            @Mapping(source = "fieldC",target = "fieldF")
    })
    List<DemoEntity> dto2entiry(List<DemoDTO> demoDTOS);

}
